#![allow(dead_code)]
mod count_num;
mod goods_bean;
mod cust_order_bean;
mod pay_type_bean;
mod status_bean;
mod order_item_bean;
mod goods_type_bean;
mod recommend_bean;
mod role_bean;
mod permission_bean;
mod user_bean;
pub mod dto;
pub mod error;

pub type CountNum = count_num::CountNum;
pub type GoodsBean = goods_bean::GoodsBean;
pub type CustOrderBean = cust_order_bean::CustOrderBean;
pub type PayTypeBean = pay_type_bean::PayTypeBean;
pub type StatusBean = status_bean::StatusBean;
pub type OrderItemBean = order_item_bean::OrderItemBean;
pub type GoodsTypeBean = goods_type_bean::GoodsTypeBean;
pub type RecommendBean = recommend_bean::RecommendBean;
pub type RoleBean = role_bean::RoleBean;
pub type PermissionBean = permission_bean::PermissionBean;
pub type UserBean = user_bean::UserBean;

pub type GoodsQueryRequest = goods_bean::GoodsQueryRequest;
pub type CustOrderQueryRequest = cust_order_bean::CustOrderQueryRequest;
pub type PayTypeQueryRequest = pay_type_bean::PayTypeQueryRequest;
pub type StatusQueryRequest = status_bean::StatusQueryRequest;
pub type OrderItemQueryRequest = order_item_bean::OrderItemQueryRequest;
pub type GoodsTypeQueryRequest = goods_type_bean::GoodsTypeQueryRequest;
pub type RecommendQueryRequest = recommend_bean::RecommendQueryRequest;
pub type RoleQueryRequest = role_bean::RoleQueryRequest;
pub type PermissionQueryRequest = permission_bean::PermissionQueryRequest;
pub type UserQueryRequest = user_bean::UserQueryRequest;

pub mod my_date_time_format {
	use chrono::NaiveDateTime;
	use serde::{self, Deserialize, Serializer, Deserializer};

	pub const DATE_TIME_FORMAT: &'static str = "%Y-%m-%d %H:%M:%S";

	pub fn serialize<S>(
		date: &Option<NaiveDateTime>,
		serializer: S,
	) -> Result<S::Ok, S::Error>
	where
		S: Serializer,
	{
		match date {
			Some(date) => {
				let s = format!("{}", date.format(DATE_TIME_FORMAT));
				serializer.serialize_str(&s)
			},
			None => serializer.serialize_str("")
		}
	}

	pub fn deserialize<'de, D>(
		deserializer: D,
	) -> Result<Option<NaiveDateTime>, D::Error>
	where
		D: Deserializer<'de>,
	{
		let s = String::deserialize(deserializer).unwrap();
		if s == "".to_string() {
			let result = NaiveDateTime::parse_from_str(&s,DATE_TIME_FORMAT).unwrap();
			Ok(Some(result))
		} else {
			Ok(Option::None)
		}
	}
}

pub mod my_date_format {
	use chrono::NaiveDate;
	use serde::{self, Deserialize, Serializer, Deserializer};
	pub const DATE_FORMAT: &'static str = "%Y-%m-%d";
	
	pub fn serialize<S>(
		date: &Option<NaiveDate>,
		serializer: S,
	) -> Result<S::Ok, S::Error>
	where
		S: Serializer,
	{
		match date {
			Some(date) => {
				let s = format!("{}", date.format(DATE_FORMAT));
				serializer.serialize_str(&s)
			},
			None => {
				serializer.serialize_str("")
			}
		}
	}

	pub fn deserialize<'de, D>(
		deserializer: D,
	) -> Result<Option<NaiveDate>, D::Error>
	where
		D: Deserializer<'de>,
	{
		let s = String::deserialize(deserializer).unwrap();
		if s == "".to_string() {
			let result = NaiveDate::parse_from_str(&s,DATE_FORMAT).unwrap();
			Ok(Some(result))
		} else {
			Ok(Option::None)
		}
	}
}
